﻿#region Copyright(C) 2018 FI Ltd. All rights reserved.
// ==================================================================================================
// Copyright(C) 2018 FI Ltd. All rights reserved.
//
// SYSTEM NAME	    : FI.Net Application Framework
// COMPONENT ID	    : FI.Core
// COMPONENT DESC   : FI.Net Core Foundation
//
// CREATED DATE/BY  : 18 Aug 2018 / Tian Mi
//
// REVISION HISTORY :	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================
#endregion

using FI.Core.IoC;
using System;

namespace FI.Core.ExceptionHandling
{
    /// <summary>
    /// A event handler to handle the exception thrown according to the specified policy.
    /// </summary>
    public interface IExceptionHandler
    {
        /// <summary>
        /// Handles the exception.
        /// </summary>
        /// <param name="exceptionToHandle">The exception to handle.</param>
        /// <param name="policyName">Name of the exception policy.</param>
        /// <param name="exceptionToThrow">The exception to throw.</param>
        /// <returns>A <see cref="bool"/> value indicating whether to throw exception.</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "2#")]
        bool HandleException(Exception exceptionToHandle, string policyName, out Exception exceptionToThrow);
    }

    [MapTo(typeof(IExceptionHandler), -10, Lifetime = Lifetime.Singleton)]
    internal class FakeExceptionHandler : IExceptionHandler
    {
        public bool HandleException(Exception exceptionToHandle, string policyName, out Exception exceptionToThrow)
        {
            throw exceptionToHandle;
        }
    }
}
